# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        博智科技  
# Name:         demo_pool
# Description:  Pool类
# Author:       yzl
# Date:         2019-04-07
#-------------------------------------------------------------------------------

from multiprocessing import Pool,cpu_count
import time

def Foo(i):
    time.sleep(2)
    return i + 100

def Bar(arg):
    print(arg)


if __name__ == '__main__':
    t_start = time.time()

    print(cpu_count())
    pool = Pool(cpu_count())

    # for i in range(10):
        # 维持执行进程总数为 processes,当一个进程执行完毕后会添加新的进程进去
    pool.apply_async(func=Foo,args=(10,),callback=Bar)

        # 同步进程 效率很低
        # pool.apply(Foo,(i,))

    pool.close()
    # 进程池中执行完毕后再关闭,如果注释程序直接关闭
    pool.join()
    t_end = time.time()

    t = t_end - t_start
    print(t)




